package com.ssm.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.sfzy.entity.Free;
import com.ssm.sfzy.mapper.FreeMapper;
import com.ssm.sfzy.service.FreeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author song
 * @date 2024年03月30日 16:02
 * @version:1.0
 */
@Service
public class FreeServiceImpl implements FreeService {

    @Autowired
    private FreeMapper freeMapper;
    @Override
    public void add(Free entity) {
        freeMapper.insert(entity);
    }

    @Override
    public void edit(Free entity) {
        freeMapper.update(entity);
    }

    @Override
    public void remove(Integer id) {
        freeMapper.delete(id);
    }

    @Override
    public void removeBatch(Integer[] ids) {
        freeMapper.deleteBatch(ids);
    }

    @Override
    public List<Free> find(Free entity) {
        return freeMapper.select(entity);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, Free entity) {
        // 分页业务
        PageHelper.startPage(pageNum,pageSize);
        // 分页查询
        List list = freeMapper.select(entity);
        // 包装查到的集合
        PageInfo<Free> pageInfo = new PageInfo<>(list);
        // 整合处理
        Map<String,Object> map = new HashMap<>();
        map.put("list",pageInfo.getList());
        map.put("total",pageInfo.getTotal());
        return map;
    }

    @Override
    public Free findById(Integer id) {
        return freeMapper.selectById(id);
    }
}
